package service;

import dao.CroBuycarsDao;
import dao.CroPurchaseDao;
import entity.CroBuycars;
import entity.CroPurchase;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import vo.CroPurchaseVo;
import vo.ParseBuycarVo;

import java.util.List;

/**
 * Created by wsx on 2017/5/19.
 */
@Service
public class FrontGoodsDetailService {
    @Autowired
    private CroBuycarsDao croBuycarsDao;
    @Autowired
    private CroPurchaseDao croPurchaseDao;

    /*
    * 获取个人的购物车
    * */
    @Transactional(readOnly = true)
    public List<CroBuycars> getPersonBuycars(String parseid) {
        StringBuffer sb = new StringBuffer();
        sb.append("from CroBuycars where purchaseid='" + parseid + "' and del_flag='0'");
        return croBuycarsDao.findByHqlExt(sb.toString(), CroBuycars.class);
    }


    /*
    * 加进购物车
    * */
    @Transactional(readOnly = false)
    public Boolean addBuycars(CroBuycars croBuycars, CroPurchase croPurchase) {
        croBuycarsDao.save(croBuycars);
        if(croPurchase!=null) {
            croPurchaseDao.save(croPurchase);
        }
        return true;
    }

    /*
   * 更新购物车
   * */
    @Transactional(readOnly = false)
    public Boolean upateBuycars(CroBuycars croBuycars) {
       croBuycarsDao.update(croBuycars);
        return true;
    }



    /*
    * 获取个人的订单
    * */
    @Transactional(readOnly = true)
    public List<CroPurchase> lists(String id) {
        StringBuilder hql = new StringBuilder();
        hql.append("from CroPurchase where order_flag='0' and costomId='" + id + "' and del_flag='0'");
        return croPurchaseDao.findByHqlExt(hql, CroPurchase.class);
    }


}
